package com.luhuiguo.cms.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.BeanNameViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

import com.luhuiguo.cms.server.web.AttachmentView;
import com.luhuiguo.cms.server.web.CmsController;
import com.luhuiguo.cms.server.web.DownloadController;
import com.luhuiguo.cms.server.web.DownloadView;
import com.luhuiguo.cms.server.web.UploadController;
import com.luhuiguo.cms.server.web.multipart.StreamingMultipartResolver;

/**
 * The spring java-based configuration for Spring-MVC.
 * 
 * @author LuHuiguo
 * @version $Id: MvcConfig.java 184 2010-05-24 10:51:16Z luhuiguo@gmail.com $
 */
@Configuration
public class MvcConfig {

    @Bean
    public MultipartResolver multipartResolver() {
        StreamingMultipartResolver multipartResolver = new StreamingMultipartResolver();
        multipartResolver.setMaxUploadSize(1000000);
        return multipartResolver;
    }

    @Bean
    public ViewResolver beanNameViewResolver() {
        BeanNameViewResolver viewResolver = new BeanNameViewResolver();
        viewResolver.setOrder(1);
        return viewResolver;
    }

    @Bean
    public ViewResolver jstlViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/jsp/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    @Bean(name = "attachment")
    public AttachmentView attachmentView() {
        return new AttachmentView();
    }

    @Bean(name = "download")
    public DownloadView downloadView() {
        return new DownloadView();
    }

    @Bean
    public UploadController uploadController() {
        return new UploadController();
    }

    @Bean
    public DownloadController downloadController() {
        return new DownloadController();
    }

    @Bean
    public CmsController cmsController() {
        return new CmsController();
    }
}
